var path = require('path')
var glob = require('glob')
var HtmlWebpackPlugin = require('html-webpack-plugin')

exports.getEntries = function(){
  var entry = {};
  var arr = glob.sync('./src/resource/js/*.js');
  arr.forEach(function(i){
    name = i.replace(/\.\/src\/resource\/js\//,'');
    name = name.replace(/\.js/,'');
    entry[name] = i;
  });
  entry['vendor']=['vue', 'n-zepto'];
  return entry;
}

exports.createHtml=function(){
  var html = glob.sync('./src/template/*.html'),arr=[],filename='',chunk='';
  html.forEach(function(i){
    filename = i.replace(/\.\/src\/template/,process.env.NODE_ENV=='development'?'.':'..');
    chunk = i.replace(/\.\/src\/template\//,'');
    chunk = chunk.replace(/\.html/,'');
    arr.push(
      new HtmlWebpackPlugin({
        filename: filename,
        template: i,
        chunks : [chunk,'vendor'],
        hash: true,
        inject: true,
        chunksSortMode: 'dependency'
      })
    );
  });
  return arr;
}
